package mirrormonkey.core.client;

import mirrormonkey.framework.ClientSyncAppState;
import mirrormonkey.framework.ConnectionInfo;

import com.jme3.network.Client;
import com.jme3.network.ClientStateListener;
import com.jme3.network.Message;
import com.jme3.network.MessageConnection;

public class ClientConnectionInfo extends ConnectionInfo implements
		ClientStateListener {

	public ClientConnectionInfo(ClientSyncAppState appState,
			MessageConnection connection) {
		super(appState, connection, true);
		appState.eventManager.addClientStateListener(this);
	}

	@Override
	public void clientConnected(Client c) {
	}

	@Override
	public void clientDisconnected(Client c, DisconnectInfo info) {
		running = false;
		((ClientSyncAppState) appState).eventManager
				.removeClientStateListener(this);
	}

	@Override
	public void send(Message m) {
		if (((Client) getConnection()).isConnected()) {
			super.send(m);
		}
	}

	public void setRunning(boolean b) {
		running = b;
	}

}
